/**将数据转换为树形结构数据格式*/
export function formatToTree(data) {
  let result = []
  if (!Array.isArray(data)) {
    return result
  }
  data.forEach(item => {
    delete item.children
  })
  let map = {}
  data.forEach(item => {
    map[item.value] = item
  })
  data.forEach(item => {
    let parent = map[item.pid]
    if (parent) {
      ;(parent.children || (parent.children = [])).push(item)
    } else {
      result.push(item)
    }
  })
  return result
}
